home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / mega src / Source / gestalt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-27  |  2.4 KB  |  113 lines  |  [TEXT/KAHL]

  1. /* ========== the commmand file: ==========
  2.  
  3.     gestalt.c
  4.     
  5.     Copyright (c) 1993,1994 Newport Software Development
  6.     
  7.     You may distribute unmodified copies of this file for
  8.     noncommercial purposes.  You may use this file as a
  9.     reference when writing your own nShell(tm) commands.
  10.     
  11.     All other rights are reserved.
  12.     
  13.    ========== the commmand file: ========== */
  14.  
  15. #include <GestaltEqu.h>
  16.  
  17. #include "nshc.h"
  18.                     
  19. #include "nshc_utl.proto.h"
  20.  
  21. int is_OSType(t_nshc_parms *nshc_parms, int arg, OSType *selector);
  22.  
  23. int is_OSType(t_nshc_parms *nshc_parms, int arg, OSType *selector)
  24. {
  25.     char    c;
  26.     char    *p;
  27.     int        i;
  28.     int        success;
  29.     
  30.     success = 1;
  31.     *selector = 0;
  32.     
  33.     p = &nshc_parms->arg_buf[ nshc_parms->argv[ arg ] ];
  34.     
  35.     for (i = 0 ; i < 4 ; i++ )
  36.         if ( c = *p++ ) {
  37.             *selector = *selector << 8;
  38.             *selector = *selector + c;
  39.             }
  40.         else
  41.             success = 0;
  42.             
  43.     if (*p) success = 0;
  44.     
  45.     return(success);
  46. }
  47.     
  48. void main(t_nshc_parms *nshc_parms, t_nshc_calls *nshc_calls)
  49. {
  50.     int        arg;
  51.     int        return_status;
  52.     OSErr    error;
  53.     OSType    selector;
  54.     long    response;
  55.     char    num_option;
  56.     
  57.     return_status = NSHC_NO_ERR;
  58.     
  59.     if (nshc_bad_version( nshc_parms, nshc_calls, NSHC_VERSION )) return;
  60.     
  61.     if ( nshc_parms->argc < 2 ) {
  62.         nshc_calls->NSH_putStr_err("\pUsage: gestalt OSType [OSType...]\r");
  63.         nshc_parms->action = nsh_idle;
  64.         nshc_parms->result = NSHC_ERR_PARMS;
  65.         return;
  66.         }
  67.     
  68.     if ( nshc_got_option( nshc_parms, 'd' ) )
  69.         num_option = 'd';
  70.     else
  71.         num_option = 'h';
  72.     
  73.     arg = 0;    // do the ones that work
  74.     
  75.     while ( arg = nshc_next_operand( nshc_parms, arg ) ) 
  76.         if ( is_OSType( nshc_parms, arg, &selector ) )
  77.          {
  78.  
  79.             error = Gestalt( selector, &response );
  80.     
  81.             if (!error) {
  82.                 if ( num_option == 'h' )
  83.                     nshc_calls->NSH_printf(  "'%.4s' %8lX\r", &selector, response );
  84.                 else
  85.                     nshc_calls->NSH_printf(  "'%.4s' %10ld\r", &selector, response );
  86.                 }
  87.                 
  88.             }
  89.  
  90.     arg = 0;    // report the ones that don't work
  91.     
  92.     while ( arg = nshc_next_operand( nshc_parms, arg ) ) 
  93.         if ( is_OSType( nshc_parms, arg, &selector ) )
  94.          {
  95.  
  96.             error = Gestalt( selector, &response );
  97.     
  98.             if (error) {
  99.                 nshc_calls->NSH_printf_err("gestalt: The selector '%.4s' produces an error = %d\r", &selector, error );
  100.                 return_status = NSHC_ERR_GENERAL;
  101.                 }
  102.                 
  103.             }
  104.         else {
  105.             nshc_calls->NSH_printf_err("gestalt: Parameter number %d is not an OSType.\r", arg );
  106.             return_status = NSHC_ERR_GENERAL;
  107.             }
  108.             
  109.     nshc_parms->action = nsh_idle;
  110.     nshc_parms->result = return_status;
  111. }
  112.  
  113.